home *** CD-ROM | disk | FTP | other *** search
/ The X-Philes (2nd Revision) / The X-Philes Number 1 (1995).iso / xphiles / hp48_1 / least.sq < prev    next >
Text File  |  1995-03-23  |  2KB  |  67 lines

  1. Article 4581 of comp.sys.handhelds:
  2. Path: en.ecn.purdue.edu!noose.ecn.purdue.edu!samsung!uunet!tut.cis.ohio-state.edu!tortoise.cis.ohio-state.edu!adkins
  3. From: adkins@tortoise.cis.ohio-state.edu (Brian Adkins)
  4. Newsgroups: comp.sys.handhelds
  5. Subject: Least Squares Approximation
  6. Message-ID: <88889@tut.cis.ohio-state.edu>
  7. Date: 26 Feb 91 18:59:10 GMT
  8. Sender: news@tut.cis.ohio-state.edu
  9. Reply-To: <adkins@tortoise.cis.ohio-state.edu>
  10. Organization: Ohio State University Computer and Information Science
  11. Lines: 52
  12.  
  13. The following is a program to perform a least squares fit on a set of 
  14. data points.  The input is as follows:
  15.  
  16. level 3: a vector of x values ie.  [1 4 5 8 10 ...]
  17. level 2: a vector of corresponding y values ie.  [3 4 5 7 6 ...]
  18. level 3: a list of names of functions ie. {F1 F2 F3 ...}
  19.  
  20. The results are a user-defined function that approximates the data in 
  21. level 2, and an error coefficient in level 1.  With the right choice of 
  22. functions the program will do linear regression (I know it's already built
  23. in!) or interpolating polynomials etc.  This is my first "real" program so
  24. I'd rather you Email me for improvements etc. instead of blasting it on the
  25. net.  Thanks.
  26.  
  27. Oh by the way, I typed this instead of uploading it so replace SQRT with
  28. the square root key and THETA with alpha-right-shift F.
  29.  
  30. <<
  31.   4 5 FOR I
  32.     DUP SIZE EVAL I ROLLD I ROLLD
  33.   NEXT
  34.   5 ROLLD 0 0 0 0 0 -> X Y N F M THETA B A C PHI 
  35.   <<
  36.     1 M FOR I
  37.       1 N FOR J
  38.         'X(J)' EVAL 'F(I)' EVAL ->NUM
  39.       NEXT
  40.       N ->ARRY
  41.     NEXT
  42.     M ->LIST 'THETA' STO 
  43.     1 M FOR I
  44.       Y 'THETA(I)' EVAL DOT
  45.     NEXT
  46.     M ->ARRY 'B' STO 
  47.     1 M FOR I
  48.       1 M FOR J
  49.         'THETA(J)' EVAL 'THETA(I)' EVAL DOT
  50.       NEXT
  51.     NEXT
  52.     M DUP 2 ->LIST ->ARRY 'PHI' STO B PHI / 'C' STO
  53.     'C(1)' EVAL { T } 'F(1)' EVAL APPLY EVAL *
  54.     2 M FOR I
  55.       'C(I)' EVAL { T } 'F(I)' EVAL APPLY EVAL * +
  56.     NEXT
  57.     ->STR 1 "=" REPL "'A(T)" SWAP + OBJ-> DEFINE
  58.     'A(X(1))-Y(1)' ->NUM SQ
  59.     2 N FOR I
  60.       'A(X(I))-Y(I)' ->NUM SQ +
  61.     NEXT
  62.     N / SQRT 'A' RCL SWAP
  63.   >>
  64. >>
  65.  
  66.  
  67.